package com.neusoft.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import com.neusoft.po.CommonResult;
import com.neusoft.po.Orders;
import com.neusoft.service.OrdersService;


@RestController
@RequestMapping("/OrdersController")
@RefreshScope
public class OrdersController {
	@Autowired
	private OrdersService ordersService;

	@PostMapping("/createOrders/{userId}/{businessId}/{daId}/{orderTotal}")
	public CommonResult createOrders(
			@PathVariable("userId") String userId, 
			@PathVariable("businessId") Integer businessId,
			@PathVariable("daId") Integer daId,
			@PathVariable("orderTotal") Double orderTotal) throws Exception {
		Orders param = new Orders();
		param.setUserId(userId);
		param.setBusinessId(businessId);
		param.setDaId(daId);
		param.setOrderTotal(orderTotal);
		int orderId = ordersService.createOrders(param);
		return new CommonResult(200, "success", orderId);
	}

	@GetMapping("/getOrdersById/{orderId}")
	public CommonResult getOrdersById(@PathVariable("orderId") Integer orderId) throws Exception {
		Orders orders = ordersService.getOrdersById(orderId);
		return new CommonResult(200, "success", orders);
	}

	@GetMapping("/listOrdersByUserId/{userId}")
	public CommonResult listOrdersByUserId(@PathVariable("userId") String userId) throws Exception {
		List<Orders> list = ordersService.listOrdersByUserId(userId);
		return new CommonResult(200, "success（10600）", list);
	}
	@PostMapping("/updateOrderStateById/{orderId}")
    public void updateOrderStateById(@PathVariable Integer orderId) throws Exception {
        ordersService.updateOrderStateById(orderId);
    }
	@PostMapping("/payOrdersById/{orderId}")
	public CommonResult payOrdersById(
			@PathVariable("orderId") Integer orderId) {
		int result=ordersService.payOrdersById(orderId);
		return new CommonResult(200, "success", result);
	}
	@PostMapping("/saveComment/{orderId}/{comment}")
	public void saveComment(
			@PathVariable("orderId") Integer orderId,
			@PathVariable("comment") String comment) throws Exception {
		ordersService.saveComment(orderId,comment);
	}
	@GetMapping("/getcomment/{businessId}")
	public CommonResult getcomment(@PathVariable("businessId") Integer businessId) throws Exception {
		List<String> result=ordersService.getcomment(businessId);
		return new CommonResult(200, "success", result);
	}

}